package com.tairanchina.md.meeting.constants;

import com.tairanchina.beego.plugin.BeegoSessionHolder;
import com.tairanchina.md.base.model.Token;
import com.tairanchina.md.meeting.entity.YearMeetingTree;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author liuxuan
 * @time 2016年10月21日
 */
public class MeetingConstants
{
    public static        ThreadLocal<UserCommonField> LOCAL        = new ThreadLocal<UserCommonField>();
    public static        String                       APP_ID       = null;
    public static        String                       APP_KEY      = null;
    public static        String                       MAXTIMES     = null;
    public static        String                       HAIWANNUM    = null;
    public static        String                       HAITAONUM    = null;
    public static        Long                         LAST_TIME    = null;
    public static        long                         INTERVAL     = 3000;


    /**
     * 年会的开始时间和结束时间
     */
    public static long STARTTIME;
    public static long ENDTIME;
    public static long MEETING_STARTTIME;
    public static long MEETING_ENDTIME;
    static{

        YearMeetingTree yearMeetingTree = MeetingProvider.treeService.findTree();
       STARTTIME = yearMeetingTree.getSatrtTime().getTime();
       ENDTIME = yearMeetingTree.getEndTime().getTime();
        MEETING_STARTTIME = yearMeetingTree.getMeetingStartTime().getTime();
        MEETING_ENDTIME = yearMeetingTree.getMeetingEndTime().getTime();
    }
    /**
     * 消息队列模块
     */
    // 年会专用(下单签到)
    public static final String EXCHANGE_NAME_YEAR_WATER = "year_party_watering_exchange";
    public static final String QUEUE_NAME_YEAR_WATER = "year_party_watering_queue";
    public static final String QUEUE_NAME_YEAR_WATER_LOCAL = "year_party_watering_queue_local";
    public static final String QUEUE_KEY_YEAR_WATER = "year_party_watering_key";

    // 年会专用(节目打赏)
    public static final String EXCHANGE_NAME_YEAR_REWARD = "year_party_reward_exchange";
    public static final String QUEUE_NAME_YEAR_REWARD = "year_party_reward_queue";
    public static final String QUEUE_KEY_YEAR_REWARD = "year_party_reward_key";

    //年会专用 本地抽奖
    public static final String EXCHANGE_NAME_YEAR_LOTTERY  = "year_party_lottery_exchange";
    public static final String QUEUE_NAME_YEAR_LOTTERY = "year_party_lottery_queue";
    public static final String QUEUE_KEY_YEAR_LOTTERY = "year_party_lottery_key";



    // 年会专用(节目点赞)
    public static final String EXCHANGE_NAME_YEAR_VOTE = "year_party_vote_exchange";
    public static final String QUEUE_NAME_YEAR_VOTE = "year_party_vote_queue";
    public static final String QUEUE_KEY_YEAR_VOTE = "year_party_vote_key";

    //阳光普照抽奖
    public static final String EXCHANGE_NAME_SUN = "year_party_sun_exchange";
    public static  String QUEUE_NAME_SUN_LOCAL = "year_party_sun_queue_local";
    public static final String QUEUE_KEY_YEAR_SUN_LOCAL = "year_party_sun_key_local";

    public static final String EXCHANGE_NAME_SUN_STATE = "year_party_sun_state_exchange";
    public static final String EXCHANGE_NAME_SUN_STATE_LOCAL = "year_party_sun_state_exchange_local";
    public static final String QUEUE_NAME_SUN_STATE = "year_party_sun_queue_state";
    public static final String QUEUE_KEY_SUN_STATE = "year_party_sun_key_state";
    public static final String QUEUE_NAME_SUN_STATE_LOCAL = "year_party_sun_queue_state_local";
    public static final String QUEUE_KEY_SUN_STATE_LOCAL = "year_party_sun_key_state_local";

    //阳光普照状态
    public static final String SUN_START = "start";
    public static final String SUN_RESET= "reset";
    public static final String SUN_STOP = "stop";


    /**
     * 节目的排序字段
     */

    public static final String PROGRAM_ORDER = "order";
    public static final String LIKE_ORDER = "like";
    public static final String TIP_ORDER  = "tip";
    public static Map<String,String> ORDER_MAP = new HashMap<String,String>();

    static{

        //节目顺序
        ORDER_MAP.put(PROGRAM_ORDER,"program_order");

        //人气值
        ORDER_MAP.put(LIKE_ORDER,"like_num desc");

        //打赏金额
        ORDER_MAP.put(TIP_ORDER,"tip_money desc");
    }


    public static void init()
    {
        if (null == LOCAL.get())
        {
            UserCommonField commonField = new UserCommonField();
            Token token = BeegoSessionHolder.getSession().get("tokenInfo", Token.class);
            commonField.setUserId(token.getUserId());
            commonField.setUserPhone(token.getPhone());
            commonField.setUserName(token.getUserName());
            LOCAL.set(commonField);
        }
    }

    public static void setUserCommonField(UserCommonField commonField)
    {
        LOCAL.set(commonField);
    }

    public static void clear()
    {
        LOCAL.set(null);
    }

    public static String getUserId()
    {
        init();
        return LOCAL.get().getUserId();
    }

    public static String getUserName()
    {
        init();
        return LOCAL.get().getUserName();
    }

    public static String getUserPhone()
    {
        init();
        return LOCAL.get().getUserPhone();
    }

    /**
     * 路由常量
     * 规则是模块前面没有‘/’，模块下面的子模块有‘/’
     */
    public class PathRoute
    {
        /**
         * 节目模块
         */
        public static final String PROGRAM_ROOT  = "/program";

        /**
         * 奖品模块
         */
        public static final String PRIZE_ROOT        = "/prize";        // 奖品根目录
        public static final String PRIZE_RANDOM      =  "/{prizeLevel}";// 抽奖
        public static final String PRIZE_PERSON_ROOT = "/person"; // 中奖人根目录

        /**
         * 阳光普照模块
         */
        public static final String SUN_ROOT = "sun";
    }

    public static final String THANK_YOU_FOR_YOUR_PATRONAGE = "谢谢惠顾";

    public static final String FLUSH_REDIS = "true";

    public static final String NOT_FLUSH_REDIS = "false";

    public static final String AWARD_DATE_FORMART = "yyyyMMdd";

    public static final String AWARD_DATE_AND_TIME_FORMART = "yyyy-MM-dd HH:mm:ss";

    public static final int GOODS_SENDING = 0;

    public static final int GOODS_SENDED = 1;

    public static final String ZERO = "0";

    public static final String ONE = "1";

    public static final String THANK_GOODS_NUM_DEFAULT = "2000";

    public static final String ORDER_BY_TIME = "award_date desc";

    public static final String ORDER_BY_CREATE = "createdon desc";

    public static final String ORDER_BY_LEVEL = "goods_level desc";

    public static final int COMMON_ZERO = 0;

    public static final int COMMON_ONE = 1;

    public static final int COMMON_TWO = 2;

    public static final int COMMON_HTREE = 3;

    public static final int COMMON_FOUR = 4;

    public static final int COME_BACK_TOMORROW = -1;

    public static final String COMMON_SPLIT_CH_COMMA = "，";

    public static final String COMMON_SPLIT_EN_COMMA = ",";

    public static final String COMMON_SPLIT_STAR = "*";

    public static final String PERCENT_SIGN = "%";

    public static final String UNDERLINE = "_";

    public static final int AWARDPOOLS = 10000;

}

